<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
	var aJaxURL		= "server-side/documents/invoice.action.php";
	var aJaxURL1	= "server-side/documents/invoice/document.action.php";		//server side folder url
	var list_aJaxURL= "server-side/documents/invoice/list.action.php";	//server side folder url
    var infName		= "in-invoice-form";								//form name
    var outfName	= "out-invoice-form";								//form name
    var tbName		= "tabs";											//tabs name

	$(document).ready(function() {
		GetTabs(tbName);
		GetOut();
		//GetIN();
		$("#tabs").tabs({disabled: [1]});
	});

	function LoadTable(tName){
		switch(tName){
			case 'out-invoice':
				//GetDataTable(tname, aJaxURL,	  action, count, data, hidden, length, sorting, sortMeth, total)
				GetDataTable(tName, aJaxURL, "get_out_list", 7, "", 0, "", 3, "desc");
				$("#search_vat_cost").css("width", "87%");
				$("#search_quantity").css("width", "87%");
				$("#search_cost").css("width", "87%");
				$("#search_serialN").css("width", "87%");
				GetButtons("", "delete_button_", "rs_sinc");
				SetEvents("", "delete_button_", "", "out-invoice", outfName, aJaxURL);
				$(document).on("click","#rs_sinc",function(){
				    $.getJSON("server-side/wsdl/invoice.action.php","act=rs_sinc",function(data){
				    	GetDataTable(tName, aJaxURL, "get_out_list", 7, "", 0, "", 3, "desc");
				    	alert(data.error);
				    });
					});


				break;
			case 'in-invoice':
				GetDataTable(tName, aJaxURL, "get_in_list", 8, "", 0, "", 0, "");
				break;
			case 'goods_list':
				var total = [4,6];
                GetDataTable(tName, list_aJaxURL, "get_list", 8, "id="+$("#invoice_id").val(), 0, "", 0, "desc", total);


				break;
		}
	}

    function LoadDialog(form) {
        switch(form){
        	case 'out-invoice-form':
                var buttons = {
    				"cancel": {
    		            text: "დახურვა",
    		            id: "cancel-dialog",
    		            click: function () {
    		                $(this).dialog("close");
    		            }
    		        }
                };
                GetDialog(outfName, 950, "auto", buttons);
                LoadTable("goods_list");
             break;
        	case 'leter':
                var buttons = {
    				"cancel": {
    		            text: "დახურვა",
    		            id: "cancel-dialog",
    		            click: function () {
    		                $(this).dialog("close");
    		            }
    		        }
                };
                GetDialog(form, "auto", "auto", buttons);
             break;
        }

    }

    function GetIN() {
        LoadTable("in-invoice");
        SetEvents("", "", "", "in-overhead", infName, aJaxURL);
    }

	function GetOut(){
        LoadTable("out-invoice");
        SetEvents("", "", "", "out-overhead", outfName, aJaxURL);
	}
function leter(id){
	GetDialog("leters", 950, "auto");
	param = new Object();
	param.act="get_edit_page";
	param.id=id;
	param.tab=1;
	param.inv="inv";
    $.ajax({
        url: aJaxURL1,
	    data:param,
        success: function(data) {
			if(typeof(data.error) != "undefined")
			{
				if(data.error != "")
				{
					alert(data.error);
				}else
				{
					$("#leters").html(data.page);
								//(tname, aJaxURL, action, count, data, hidden, length, sorting, sortMeth, total)
					GetDataTable('table-3', aJaxURL1, "get_list", 5 , "tab=3&id="+$('#inv_id').val(), 0, "", 1, "asc", [3]);
					//SetEvents(, , , tname, fname, aJaxURL, c_data, c_param)
					SetEvents('','','','table-3',"leter",aJaxURL1);
				}
			}
	    }
    });


}
</script>
</head>
<body>
	<div id="tabs" style="width: 1024px; margin: 0 auto; min-height: 768px;">
		<ul>
			<li><a href="#tab-out">გაცემული</a></li>
			<li><a href="#tab-in">მიღებული</a></li>
		</ul>
		<div id="tab-out">
			<div id="dt_example" class="ex_highlight_row">
				<div id="container" class="overhead_container">
					<div id="dynamic">
						<h2>გაცემული ანგარიშ–ფაქტურები</h2>
						<div id="button_area">
						<button id="rs_sinc">რ/ს.ჯი  სინქ. </button>
						<button id="delete_button_">წაშლა</button>
						</div>
						<table class="display" id="out-invoice">
							<thead>
								<tr id="datatable_header">
									<th>ID</th>
									<th style="width: 110px;">სერია №</th>
									<th style="width: 100%">პარტნიორი</th>
									<th class="min">ოპერაციის თარ.</th>
									<th style="width: 70px;">თანხა</th>
									<th style="width: 100px;">დეტალურად</th>
									<th style="width: 140px;">სტატუსი</th>
									<th style="width: 35px;">#</th>
								</tr>
							</thead>
							<thead>
								<tr class="search_header">
									<th class="colum_hidden">
										<input type="text" name="search_id" id="search_id" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" name="search_partner" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" name="search_doc_date" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" id="search_cost" name="search_cost" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" id="search_quantity" name="search_quantity" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" id="search_vat_cost" name="search_vat_cost" value="ფილტრი" class="search_init" />
									</th>
									<th>
										<input type="text" name="search_status" value="ფილტრი" class="search_init" />
									</th>
									<th>

									</th>
								</tr>
							</thead>
							 <tfoot>
		                        <tr>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                            <th>&nbsp;</th>
		                             <th>&nbsp;</th>
		                        </tr>
                    </tfoot>
						</table>
					</div>
					<div class="spacer"></div>
				</div>
			</div>
		</div>
		<div id="tab-in">
			<div id="dt_example" class="ex_highlight_row">

				<div id="container" class="overhead_container">
					<div id="dynamic">
						<h2>მიღებული ანგარიშ–ფაქტურები</h2>
						<div id="button_area">
						</div>
						<table class="display" id="in-invoice">
						</table>
					</div>
					<div class="spacer"></div>
				</div>
			</div>
		</div>
	</div>
	<div id="leters" class="form-dialog" title="მიღებული ანგარიშ–ფაქტურები">
		<!-- aJax -->
	</div>

	<div id="leter" class="form-dialog" title="ბარათები">
		<!-- aJax -->
	</div>
	<!-- jQuery Dialog -->
	<div id="in-invoice-form" class="form-dialog" title="მიღებული ანგარიშ–ფაქტურები">
		<!-- aJax -->
	</div>

	<div id="out-invoice-form" class="form-dialog" title="გაცემული ანგარიშ–ფაქტურები">
		<!-- aJax -->
	</div>

</body>
</html>